﻿using Microsoft.SharePoint;
using Eneta.Portal.Common;
using Eneta.Portal.Common.Definitions;

namespace Eneta.Portal.Site
{
    public class ContentTypesFeatureReceiver : SPFeatureReceiver
    {
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            var web = properties.Feature.Parent as SPWeb;
            if (web == null)
                web = ((SPSite)properties.Feature.Parent).RootWeb;

            //web.AddFieldToContentType("EnetaKeywords", "Raamat");
            //web.AddFieldToContentType("EnetaKeywords", "Ajakiri");

            var blogEntryCtId = new SPContentTypeId(ContentTypes.BlogEntry);
            web.AddFieldToContentType(BlogEntryFields.Keywords, blogEntryCtId);

            var annId = new SPContentTypeId(ContentTypes.Announcement);
            web.AddFieldToContentType(AnnouncementFields.Keywords, annId);

            var companyId = new SPContentTypeId(ContentTypes.Company);
            web.AddFieldToContentType(CompanyFields.Offices, companyId);
        }

        public static void AddFields(SPWeb web)
        {
            var blogEntryCtId = new SPContentTypeId(ContentTypes.BlogEntry);
            web.AddFieldToContentType(BlogEntryFields.Keywords, blogEntryCtId);

            var annId = new SPContentTypeId(ContentTypes.Announcement);
            web.AddFieldToContentType(AnnouncementFields.Keywords, annId);

            var companyId = new SPContentTypeId(ContentTypes.Company);
            web.AddFieldToContentType(CompanyFields.Offices, companyId);
        }
    }
}
